using System.Diagnostics;
using System.Collections.Generic;
using System.Text;

//
// * Copyright (c) 2002-2009 "Neo Technology,"
// *     Network Engine for Objects in Lund AB [http://neotechnology.com]
// *
// * This file is part of Neo4j.
// * 
// * Neo4j is free software: you can redistribute it and/or modify
// * it under the terms of the GNU Affero General Public License as
// * published by the Free Software Foundation, either version 3 of the
// * License, or (at your option) any later version.
// * 
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// * GNU Affero General Public License for more details.
// * 
// * You should have received a copy of the GNU Affero General Public License
// * along with this program. If not, see <http://www.gnu.org/licenses/>.
// 
namespace org.neo4j.kernel.impl.nioneo.store
{


	public class PropertyRecord : AbstractRecord
	{
		private PropertyType type;
		private int keyIndexId = Record.NO_NEXT_BLOCK.intValue();
		private long propBlock = Record.NO_NEXT_BLOCK.intValue();
		private int prevProp = Record.NO_PREVIOUS_PROPERTY.intValue();
		private int nextProp = Record.NO_NEXT_PROPERTY.intValue();
		private List<DynamicRecord> valueRecords = new List<DynamicRecord>();
		private bool isLight = false;
		private int nodeRelId = -1;
		private bool nodeIdSet = false;

		public PropertyRecord(int id) : base(id)
		{
		}

		public virtual void setType(PropertyType type)
		{
			this.type = type;
		}

		public virtual void setNodeId(int nodeId)
		{
			nodeIdSet = true;
			nodeRelId = nodeId;
		}

		public virtual void setRelId(int relId)
		{
			nodeIdSet = false;
			nodeRelId = relId;
		}

		public virtual int getNodeId()
		{
			if (nodeIdSet)
			{
				return nodeRelId;
			}
			return -1;
		}

		public virtual int getRelId()
		{
			if (!nodeIdSet)
			{
				return nodeRelId;
			}
			return -1;
		}

		internal virtual void setIsLight(bool status)
		{
			isLight = status;
		}

		public virtual bool isLight()
		{
			return isLight;
		}

		public virtual Collection<DynamicRecord> getValueRecords()
		{
			Debug.Assert(!isLight);
			return valueRecords;
		}

		public virtual void addValueRecord(DynamicRecord record)
		{
			Debug.Assert(!isLight);
			valueRecords.Add(record);
		}

		public virtual PropertyType getType()
		{
			return type;
		}

		public virtual int getKeyIndexId()
		{
			return keyIndexId;
		}

		public virtual void setKeyIndexId(int keyId)
		{
			this.keyIndexId = keyId;
		}

		public virtual long getPropBlock()
		{
			return propBlock;
		}

		public virtual void setPropBlock(long propBlock)
		{
			this.propBlock = propBlock;
		}

		public virtual int getPrevProp()
		{
			return prevProp;
		}

		public virtual void setPrevProp(int prevProp)
		{
			this.prevProp = prevProp;
		}

		public virtual int getNextProp()
		{
			return nextProp;
		}

		public virtual void setNextProp(int nextProp)
		{
			this.nextProp = nextProp;
		}

		public override string ToString()
		{
			StringBuilder buf = new StringBuilder();
			buf.Append("PropertyRecord[").Append(getId()).Append(",").Append(inUse()).Append(",").Append(type).Append(",").Append(keyIndexId).Append(",").Append(propBlock).Append(",").Append(prevProp).Append(",").Append(nextProp);
			buf.Append(", Value[");
			foreach (DynamicRecord record in valueRecords)
			{
				buf.Append(record);
			}
			buf.Append("]]");
			return buf.ToString();
		}
	}
}